//implement IO operations on a drive
#pragma once
#include "Stream.h"

namespace System
{
	enum DriveType
	{
		NTFS,
		FAT,
		NONE,//just raw reading the disk!
	};

	typedef struct SYSTEM_API
	{
		WORD	wCylinder;
		WORD	head;
		WORD	sector;
		DWORD	nSectors;
		WORD	type;
		DWORD	firstPartitionSector;
		DWORD	NTRelativeSector;
		DWORD	bytesPerSector;
	}DriveInfo;
	
	typedef std::map<std::string, DriveInfo>					DriveList;
	typedef std::map<std::string, DriveInfo>::iterator			DriveI;
	typedef std::map<std::string, DriveInfo>::const_iterator	DriveCI;

	namespace IO
	{

		class SYSTEM_API DriveStream : public Stream
		{
		public:
			DriveStream(DriveInfo driveInfo, DriveType type, char* name = "\\.\\\\PhysicalDrive0");
			void init(const char* name);

			virtual ~DriveStream(void);
			virtual int  read(MemoryBuffer& memBuf, int offset, size_t count);
			virtual int  readByte(byte& value);
			ud_uint64 seek(ud_uint64 offset);

			virtual ud_uint64 seek(ud_uint64 offset, SeekOrigin origin);

			virtual void setLength(ud_uint64 value);
			virtual int write(const MemoryBuffer& memBuf, int offset, size_t count);
			virtual void writeByte(byte value);
			
			void initDriveInformation(DriveInfo driveInfo);
		private:

			char*					m_diskName;
			HANDLE					m_handle;
			bool					m_openSuccesfull;
			
			DriveInfo				m_driveInfo;
			DriveType				m_driveType;
		};
	}
}